package com.czxy.tanhua.exception;

import com.czxy.tanhua.vo.ErrorResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @Author 爱吃豆的土豆、
 * @Date 2023/4/4 11:04
 */
@ControllerAdvice
public class ExceptionAdvice {
    /**
     * 业务异常
     */
    @ExceptionHandler(BusinessException.class)
    public ResponseEntity businessException(BusinessException be){
        be.printStackTrace();
        return ResponseEntity.status(500).body(be.getErrorResult());
    }
    /**
     * 通用异常
     */
    @ExceptionHandler(Exception.class)
    public ResponseEntity exception(Exception e){
        e.printStackTrace();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ErrorResult.error());
    }
}
